<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改密码</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/font-awesome.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/default/layer.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <div class="form-horizontal">
                            <div class="form-group">
                                <form class="form-horizontal m-t" id="commentForm">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label class="col-xs-3 control-label">昵称:</label>
                                            <div class="col-xs-9">
                                                <input type="text" class="form-control" id="nick_name" name="nick_name" aria-required="false" placeholder="请输入昵称">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label class="col-xs-3 control-label">联系方式:</label>
                                            <div class="col-xs-9">
                                                <input type="text" placeholder="请输入联系方式" class="form-control" name="mobile" id="mobile" aria-required="false" maxlength="11"
                                                    onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label class="col-xs-3 control-label">邮箱:</label>
                                            <div class="col-xs-9">
                                                <input type="email" class="form-control" id="email" name="email" aria-required="false" placeholder="请输入邮箱地址">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label class="col-xs-3 control-label">头像:</label>
                                            <div class="col-xs-9">
                                                <input type="text" placeholder="请输入头像图片地址" class="form-control" id="head_portrait" name="head_portrait" aria-required="false">
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-xs-3 col-xs-offset-3">
                                    <button class="btn btn-success" type="submit">确定</button>
                                </div>
                                <div class="col-xs-3">
                                    <button class="btn btn-danger" type="submit">取消</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 全局js -->
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!-- 自定义js -->
    <script src="js/content.js"></script>
    <script src="js/plugins/layer/layer.min.js"></script>
    <script src="js/plugins/layer/layer.js"></script>
    <script src="js/plugins/validate/jquery.validate.min.js"></script>
    <script src="js/plugins/validate/messages_zh.min.js"></script>
    <script src="js/work/common.js"></script>
    <script>
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        $(document).ready(function () {
            $("#commentForm").validate({
                rules: {
                    email: {
                        email: true,
                        required: false
                    },
                    mobile: {
                        minlength: 11,
                        required: false,
                    },
                }
            })
            initUser()
        });

        function initUser() {
            // ajax({
            //     url: "userInfoMain/queryUpmsUserInfo",
            //     data: {},
            //     successx: function (data) {
            //
            //         if (data.success) {
            //
            //             createaUser(data.data)
            //         } else {
            //             parent.layer.msg(data.message)
            //         }
            //     }
            // })
        }
        function createaUser(data){
            $("#nick_name").val(data.nick_name);
            $("#mobile").val(data.mobile);
            $("#email").val(data.email);
            $("#head_portrait").val(data.head_portrait)
        }
        $(".btn-danger").on("click", function () {
            parent.layer.close(index);
        });
        var flag = 0;
        $(".btn-success").on("click", function () {
            var mobile = $("#mobile").val();;
            var email = $("#email").val();;
            var nick_name = $("#nick_name").val();;
            var head_portrait = $("#head_portrait").val();;
            if (nick_name == "登机区官方") {
                layer.msg("昵称不合法");
                return
            }
            if (!isNULL(email)) {
                var reg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
                if (!reg.test(email)) {
                    layer.msg("邮箱格式有误");
                    return
                }
            }
            if (!(/^(0|86|17951)?(13[0-9]|15[012356789]|17[0-9]|18[0-9]|14[57])[0-9]{8}$/.test(mobile))) {
                layer.msg("手机号码格式不正确");
                return
            }
            if (flag == 1) return;
            flag = 1;
            ajax({
                url: "userInfoMain/updateUserInfo",
                data: {
                    head_portrait: head_portrait,
                    nick_name: nick_name,
                    mobile:mobile,
                    email:email
                },
                successx: function (data) {
                    setTimeout(function(){
                        flag=0;
                    },200)
                    if (data.success) {
                        parent.layer.msg(data.message)                       
                        setTimeout(function () {
                            parent.layer.close(index);
                        }, 2000)

                    } else {
                        parent.layer.msg(data.message)
                    }
                }
            })

        });
    </script>
</body>

</html>